home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / pcxkt3.zip / HOEDOWN.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-02  |  3KB  |  129 lines

  1. program HOEDOWN;
  2.  
  3. (*
  4.    Demonstration of animation against a backdrop. See CLIP.DOC.
  5.  
  6.    Before compiling this program, set the "pathtodrivers" constant to the
  7.    directory where your .BGI files reside.
  8. *)
  9.  
  10. uses GRAPH, CRT;
  11.  
  12. const  pathtodrivers = 'C:\TP\BGI';
  13.        datafile = 'HOEDOWN.DTA';
  14.        step = 10;                { Governs lateral motion of figure }
  15.        ypos = 100;               { Top line of images }
  16.  
  17. type   imagetype = record
  18.           width, height, size, xpos: integer;
  19.           image, backdrop: pointer;
  20.        end;
  21.  
  22. var   grdriver, grmode, grerror: integer;
  23.       pal: palettetype;
  24.       icon_file: file;
  25.       x, page: integer;
  26.       Clem: array[0..1] of imagetype;
  27.       bales: imagetype;
  28.       junk: char;
  29.  
  30. (* ----------------------------------------------------------------------- *)
  31.  
  32. procedure GET_ICON(var pic: imagetype);
  33.  
  34. begin
  35. with pic do
  36. begin
  37.   blockread(icon_file, width, 2);             { Dimensions first }
  38.   blockread(icon_file, height, 2);
  39.   size:= imagesize(0, 0, width, height);
  40.   getmem(image, size);                        { Allocate dynamic memory }
  41.   getmem(backdrop, size);
  42.   seek(icon_file, filepos(icon_file) - 4);
  43.   blockread(icon_file, image^, size);         { Store the image }
  44. end;
  45. end;
  46.  
  47. (* ----------------------------------------------------------------------- *)
  48.  
  49. BEGIN
  50.  
  51. (* Open data file and quit if not found. The file consists of the palette
  52.    record followed by three images - two of the dancing man and one of
  53.    the bales that form the backdrop. *)
  54.  
  55. assign(icon_file, datafile);
  56. {$I-} reset(icon_file, 1);  {$I+}
  57. if IOresult <> 0 then
  58. begin
  59.   writeln('File ',datafile,' not found.');
  60.   halt;
  61. end;
  62.  
  63. (* Initialize graphics *)
  64.  
  65. grmode:= egahi; grdriver:= ega;
  66. initgraph(grdriver, grmode, pathtodrivers);
  67. grerror:= graphresult;
  68. if grerror <> 0 then
  69. begin
  70.   writeln('Graphics error: ',grapherrormsg(grerror));
  71.   halt;
  72. end;
  73.  
  74. (* Read the palette from file and set the colors *)
  75.  
  76. blockread(icon_file, pal, 17);
  77. setallpalette(pal);
  78.  
  79. (* Initialize the position of the images *)
  80.  
  81. Clem[1].xpos:= 590; Clem[0].xpos:= Clem[1].xpos - step div 2;
  82.  
  83. (* Get the images into memory *)
  84.  
  85. for x:= 0 to 1 do get_icon(Clem[x]);
  86. get_icon(bales);
  87. close(icon_file);
  88.  
  89. (* Draw the scenic backdrop on both video pages, and store the part
  90.    that will be written to the screen when the loop is entered *)
  91.  
  92. for page:= 0 to 1 do
  93. with bales do
  94. begin
  95.   xpos:= 20;
  96.   setactivepage(page);
  97.   setvisualpage(page xor 1);
  98.   repeat
  99.     putimage(xpos, ypos, image^, copyput);
  100.     inc(xpos, width);
  101.   until xpos > getmaxx;
  102.   with Clem[page] do
  103.     getimage(xpos, ypos, xpos+width, ypos+height, backdrop^);
  104. end;
  105.  
  106. (* Now flip between the two video pages. While one page is being viewed,
  107.    update the other. First copy the stored backdrop over the dancing
  108.    figure, then increment his position, then store the backdrop at
  109.    his new position, and finally redraw him. *)
  110.  
  111. page:= 1;
  112. repeat
  113.   with Clem[page] do
  114.   begin
  115.     setactivepage(page);
  116.     setvisualpage(page xor 1);
  117.     putimage(xpos, ypos, backdrop^, copyput);
  118.     dec(xpos, step);
  119.     if xpos < 0 then xpos:= 590;
  120.     getimage(xpos, ypos, xpos+width, ypos+height, backdrop^);
  121.     putimage(xpos, ypos, image^, orput);
  122.     delay(200);
  123.     page:= page xor 1;
  124.   end;
  125. until keypressed;
  126. junk:= readkey;     { Discard keypress }
  127. closegraph;
  128. END.
  129.